<% login_user_id = session[:user_id] -%>

<div class="bookmark_space" style="border-bottom: 1px solid silver; padding-bottom: 5px; margin-bottom: 10px; position: relative;">
<% if @create_button_show %>
  <div style="position: absolute; top: 5px; right: 10px;">
    <%= link_to(icon_tag('tag_blue_add', :alt=>'コメントの追加') + 'コメントの追加！', {:controller => "bookmark", :action => "edit", :url => @bookmark.url, :title => @bookmark.title, :dummy => '.html'}, {:class => "nyroModal"}) %>
  </div>
<% end %>
  <div class="title"><%= link_to_bookmark_url(@bookmark, @bookmark.title) %> </div>
  [タグ]
  <div style="margin: 5px 10px; background-color: #fff0f0; padding: 5px;">

<% tag_cloud @tags do |name, count, css_class| -%>
<%= link_to name, {:controller => "bookmarks", :action => "search", :tag_words => name}, :class => css_class -%>
<span style='color: silver; font-size: 10px;'>(<%= count -%>)</span>
<% end -%>
  </div>
  <div style="overflow: hidden;">[URL]　<%= link_to_bookmark_url(@bookmark, @bookmark.url) %></a><br>
       [登録ユーザ]　<%=h @bookmark.bookmark_comments_count %>人<span style="font-size: 10px;">(非公開の人数含む) </span></div>
</div>

<% @bookmark.bookmark_comments.reverse! %>
<% @bookmark.bookmark_comments.each do |bookmark_comment| %>
  <% if bookmark_comment.user_id ==login_user_id || bookmark_comment.public == true %>
    <div class="comment_space" <%= " style='background-color: lightyellow;'" if bookmark_comment.user.id == login_user_id %>>
      <span style='font-size:10px;'><%= bookmark_comment.updated_on.strftime("%Y年%m月%d日") if bookmark_comment.updated_on %></span>
      <span><%= user_link_to bookmark_comment.user, :image_on => true %></span>
      <span style='font-size:10px; color: blue;'><%=h bookmark_comment.tags %></span>
      <span><%=h bookmark_comment.comment %></span>
    <% if bookmark_comment.user.id == login_user_id %>
      <%= icon_tag('key', :title=>"非公開") unless bookmark_comment.public -%>
      <%= link_to(icon_tag('tag_blue_edit', :alt => '編集'), {:controller => "bookmark", :action => "edit", :url => @bookmark.url, :title => @bookmark.title, :dummy => '.html'}, {:class => "nyroModal"}) %>
      <%= link_to_function icon_tag('tag_blue_delete', :alt => '削除'),"if (confirm('本当に削除しますか')) { var f = document.createElement('form'); this.parentNode.appendChild(f); f.method = 'POST';f.action = get_action_value(this.href, #{bookmark_comment.id}); f.submit();}",:href => url_for(:controller =>'bookmark', :action =>'destroy')  %>
    <% end %>
    </div>
  <% end %>
<% end %>

<script  language='javascript' type='text/javascript'>
function get_action_value(href, comment_id){
  return  href +'/' +  escape('<%= @bookmark.get_encode_url %>') + '?comment_id=' + comment_id;
}
</script>
